package org.thomias.exo1.udp;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Client {

	public void start() {
		DatagramSocket socket = null;
		try {
			socket = new DatagramSocket();
			BufferedReader inFile = new BufferedReader(new FileReader(
					"test.txt"));
			String read;
			while ((read = inFile.readLine()) != null) {
				byte[] sendData = (read).getBytes();
				DatagramPacket sendPacket = new DatagramPacket(sendData,
						sendData.length, InetAddress.getByName("127.0.0.1"),
						22222);
				System.out.println("About to send: " + new String(sendData));
				socket.send(sendPacket);
			}
			inFile.close();
			byte[] sendData = "quit".getBytes();
			DatagramPacket sendPacket = new DatagramPacket(sendData,
					sendData.length, InetAddress.getByName("127.0.0.1"), 22222);
			System.out.println("About to send: " + new String(sendData));
			socket.send(sendPacket);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			socket.close();
		}

	}

}
